//
//  ViewController.swift
//  UITextField自定义leftView
//
//  Created by 李煜 on 2023/3/14.
//

import UIKit

class ViewController: UIViewController {
  let acText: ACTextField = .init(frame: .init(x: 100, y: 140, width: 200, height: 44))
  let leftText: UITextField = .init(frame: .init(x: 100, y: 230, width: 200, height: 44))
  let text: UITextField = .init(frame: .init(x: 100, y: 300, width: 200, height: 44))

  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .init(white: 0.8, alpha: 1)

    acText.borderStyle = .roundedRect
    view.addSubview(acText)
    acText.icon = UIImage(systemName: "phone")

//    添加左边距
    leftText.borderStyle = .roundedRect
    view.addSubview(leftText)
    let img1 = UIImage(systemName: "trash.fill")
    leftText.addLeftTextPadding(20)
    // tint只在leftview设置有效
    leftText.leftView?.tintColor = .systemGreen

    text.borderStyle = .roundedRect
    view.addSubview(text)
    // 此步骤设置orange无效
    let img2 = UIImage(systemName: "trash.fill")!.withTintColor(.orange)
    text.addLeftIcon(img2, frame: .init(x: 0, y: 0, width: 44, height: 44), imageSize: CGSize(width: 36, height: 36))
    // tint只在leftview设置有效
    text.leftView?.tintColor = .systemGreen
  }
}
